<template>
  <div class="panel">
    <el-dialog title="编辑权限" :visible="showdialog" @close="cancel">
      <el-form :model="formData" label-width="100px">
        <el-form-item label="权限名称" prop="name"><el-input v-model="formData.name" /></el-form-item>
        <el-form-item label="权限标识" prop="code"><el-input v-model="formData.code" /></el-form-item>
        <el-form-item label="权限描述" prop="description"><el-input v-model="formData.description" /></el-form-item>
        <el-form-item label="企业可见">
          <span :class="{switchcolor:formData.enVisible==0}">不可见</span>
          <el-switch
            v-model="formData.enVisible"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="1"
            inactive-value="0"
          />
          <span :class="{switchcolor:formData.enVisible==1}">可见</span></el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getPerApi, updatePerApi } from '@/api/permission'
export default {
  props: ['showdialog', 'updateye'],
  data() {
    return {
      formData: {
        name: '', // 权限名称
        code: '', // 权限标识
        description: '', // 权限描述
        enVisible: '', // 是否可见
        id: '', // 角色的id
        type: '', // 菜单等级
        pid: '',
        _id: ''
      },
      // switch开关
      switchshow: false
    }
  },
  methods: {
    // 打开编辑面板的时候根据ID获取权限点详情
    async getPer(id) {
      const res = await getPerApi(id)
      console.log(res)
      this.formData = res
    },
    // 取消按钮事件
    cancel() {
      this.$emit('update:showdialog', false)
    },
    // 提交修改按钮
    async submit() {
      try {
        // 发送网络请求
        const res = await updatePerApi(this.formData)
        console.log(res)
        // 关闭面板
        this.$emit('update:showdialog', false)
        // 提示操作成功
        this.$message.success('修改成功')
        // 更新页面
        this.$emit('updateye')
      } catch {
        console.log('修改失败')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.panel{
    .switchcolor{
        color:aqua
    }
}
</style>
